﻿$(function() {

    $('#div_search').window({
        iconCls: 'icon-search',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '查询信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 260,
        // height: 350,
        closed: true,
        onOpen: function() {
            $('#div_search').parent().css("left", "25%");
            $('#div_search').parent().next().css("left", "25%");
            $('#div_search').parent().next().css("top", "25%");
            $('#div_search').parent().css("top", "25%");
        }
    });

    $("#tree").tree({
        //"../Project/Handler/ProjectPayBackTreeHandler.ashx?type=ProjectPayBackInfo&id=01-01-01-01",
        url: "../../Project/Handler/ProjectPayBackTreeHandler.ashx?internaltype=1",
        animate: true,
        onSelect: function(node) {
            if (node == null || node.attributes == null) return;
            var nodes = $("#tree").tree("getChildren", node.target);
            $.each(nodes, function(i, no) {
                $("#tree").tree("remove", no.target);
            });
            var id = node.id;
            var url1 = "../../Project/Handler/ProjectPayBackTreeHandler.ashx?type=" + node.attributes["type"] + "&id=" + id;
            $.ajax({
                type: "post",
                url: url1,
                data: "",
                dataType: "json",
                success: function(data) {
                    $("#tree").tree("append",
                    { parent: node.target,
                        data: data
                    });
                }
            });
        }
    });
});

function searchTree() {
    var url = "../../Project/Handler/ProjectPayBackTreeHandler.ashx?internaltype=1";
    if ($("#ProjectNum").val() != "undefined") {
        url += "&prjectNum=" + $("#ProjectNum").val();
    }
    if ($("#ProjectName").val() != "undefined") {
        url += "&projectName=" + $("#ProjectName").val();
    }
    if ($("#ProjectNum").val() == 'undefined' && $("#ProjectName").val() == "undefined") {
        $('#div_search').window('close');
        return;
    }
    $("#tree").tree({
        url: url
    });
    $('#div_search').window('close');
}